import { BasicColumn, FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { DescItem } from '/@/components/Description/index';
import { useI18n } from '/@/hooks/web/useI18n';
import { listAllPayIfDefine } from '../payIfDefine/payIfDefine.api'
import { h } from 'vue';
import OpenOrderDetail from './OpenOrderDetail.vue';

const { t } = useI18n('');

export const columns: BasicColumn[] = [
  {
    title: t('订单号'),
    dataIndex: 'orderNo',
    fixed: 'left',
    width: 180,
  },
  {
    title: t('支付接口'),
    dataIndex: 'ifCode',
    width: 130,
  },
  {
    title: t('差异类型'),
    dataIndex: 'diffType',
    width: 130,
    customRender: ({ record }) => {
      const { diffTypeText, diffType } = record as any
      let color = 'green'
      if (diffType === '2') {
        color = 'cyan'
      } else if (diffType === '3') {
        color = 'blue'
      }
      return render.renderTag(diffTypeText, color)
    }
  },
  {
    title: t('账单类型'),
    dataIndex: 'billType',
    width: 130,
    customRender: ({ record }) => {
      const { billTypeText, billType } = record as any
      let color = 'green'
      if (billType === '2') {
        color = 'cyan'
      } 
      return render.renderTag(billTypeText, color)
    }
  },

  {
    title: t('交易状态'),
    dataIndex: 'tradeStatus',
    slot: 'tradeStatus',
    width: 130,
  },
  {
    title: t('交易金额'),
    dataIndex: 'tradeAmount',
    slot: 'tradeAmount',
    width: 100,
  },

  {
    title: t('处理状态'),
    dataIndex: 'handleStatus',
    width: 130,
    customRender: ({ record }) => {
      const { handleStatusText, handleStatus } = record as any
      let color = 'orange'
      if (handleStatus === '2') {
        color = 'cyan'
      } else if (handleStatus === '3') {
        color = 'green'
      } else if (handleStatus === '4') {
        color = 'purple'
      } 
      return render.renderTag(handleStatusText, color)
    }
  },
  {
    title: t('批次号'),
    dataIndex: 'batchNo',
    width: 280,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: t('批次号'),
    field: 'batchNo',
    component: 'Input',
  },
  {
    label: t('订单号'),
    field: 'orderNo',
    component: 'Input',
    componentProps: {
      placeholder: '支付/退款订单号',
      allowClear: true,
    },
  },
  {
    label: t('账单日期'),
    field: 'billDate',
    component: 'RangePicker',
    componentProps: {
      valueType: 'Date',
    },
  },
  {
    label: t('账单类型'),
    field: 'billType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'pay_check_bill_type',
      placeholder: '全部',
      chooseOptionLabel: '全部',
      allowClear: true,
    },
  },
  {
    label: t('差异类型'),
    field: 'diffType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'pay_check_diff_type',
      placeholder: '全部',
      chooseOptionLabel: '全部',
      allowClear: true,
    },
  },
  {
    label: t('处理状态'),
    field: 'handleStatus',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'pay_check_diff_handle_status',
      placeholder: '全部',
      chooseOptionLabel: '全部',
      allowClear: true,
    },
  },
  {
    label: t('支付接口'),
    field: 'ifCode',
    component: 'ApiSelect',
    componentProps: {
      api: listAllPayIfDefine,
      showSearch: true,
      allowClear: true,
      placeholder: '全部',
      resultField: 'data',
      labelField: 'ifName',
      valueField: 'ifCode',
    },
  },
  {
    label: t('应用ID'),
    field: 'appId',
    component: 'Input',
  },

];


export const formDetailSchema: DescItem[] = [
  {
    field: 'diffType',
    label: t('差异类型'),
    render: (curVal, data) => {
      return render.renderTag(data.diffTypeText, 'red')
    }
  },
  {
    field: 'handleStatusText',
    label: t('处理状态')
  },
  {
    label: t('批次号'),
    field: 'batchNo'
  },
  {
    label: t('账单日期'),
    field: 'billDate'
  },
  {
    field: 'billTypeText',
    label: t('账单类型')
  },
  {
    label: t('支付接口'),
    field: 'ifCode'
  },
  {
    label: t('订单号'),
    field: 'orderNo',
    render: (curVal, data) => {
      return h(OpenOrderDetail, { orderNo:  curVal})
    },
  },
  {
    label: t('说明'),
    field: 'remark'
  },

  {
    label: t('创建时间'),
    field: 'createdAt'
  },
  {
    label: t('处理时间'),
    field: 'updatedAt'
  },
  {
    label: t('处理者名称'),
    field: 'updatedBy'
  },
  {
    label: t('处理者ID'),
    field: 'updatedUid'
  },
  {
    label: '',
    field: 'drivider',
    render: (curVal, data) => {
      return render.renderDividerWithValue('平台账单')
    },
    show: ({ diffType, handleStatus }) => diffType != '2' || handleStatus === '3',
    span: 2
  },
  {
    label: t('订单状态'),
    field: 'orderStatusText',
    show: ({ diffType, handleStatus }) => diffType != '2' || handleStatus === '3',
  },
  {
    label: t('交易金额'),
    field: 'orderAmount',
    show: ({ diffType, handleStatus }) => diffType != '2' || handleStatus === '3',
  },
  {
    label: t('平台手续费'),
    field: 'feeAmount',
    show: ({ diffType, handleStatus }) => diffType != '2' || handleStatus === '3',
  },
  {
    label: t('交易创建时间'),
    field: 'orderCreatedAt',
    show: ({ diffType, handleStatus }) => diffType != '2' || handleStatus === '3',
  },
  {
    label: t('交易成功时间'),
    field: 'orderSuccessAt',
    show: ({ diffType, handleStatus }) => diffType != '2' || handleStatus === '3',
  },
  
  {
    label: t('商户号'),
    field: 'mchNo',
    show: ({ diffType, handleStatus }) => diffType != '2' || handleStatus === '3',
  },
  {
    label: t('商户应用ID'),
    field: 'appId',
    show: ({ diffType, handleStatus }) => diffType != '2' || handleStatus === '3',
    span: 2
  },
  {
    label: '',
    field: 'drivider',
    render: (curVal, data) => {
      return render.renderDividerWithValue('渠道账单')
    },
    show: ({ diffType, handleStatus }) => diffType != '1' || handleStatus === '3',
    span: 2
  },
  {
    label: t('渠道订单状态'),
    field: 'channelStatusText',
    show: ({ diffType, handleStatus }) => diffType != '1' || handleStatus === '3',
  },
  {
    label: t('渠道订单号'),
    field: 'channelOrderNo',
    show: ({ diffType, handleStatus }) => diffType != '1' || handleStatus === '3',
  },
  {
    label: t('渠道交易金额'),
    field: 'channelAmount',
    show: ({ diffType, handleStatus }) => diffType != '1' || handleStatus === '3',
  },
  {
    label: t('渠道手续费'),
    field: 'channelFeeAmount',
    show: ({ diffType, handleStatus }) => diffType != '1' || handleStatus === '3',
  },
  {
    label: t('渠道商户号'),
    field: 'channelMchNo',
    show: ({ diffType, handleStatus }) => diffType != '1' || handleStatus === '3',
  },
  {
    label: t('渠道交易成功时间'),
    field: 'channelSuccessAt',
    show: ({ diffType, handleStatus }) => diffType != '1' || handleStatus === '3',
  },

];
